package com.bobo.mapper;

import com.bobo.dto.VoucherPageQueryDTO;
import com.bobo.entity.Voucher;
import com.bobo.entity.VoucherOrder;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface VoucherMapper {

    Long addVoucher(Voucher voucher);
    @Select("select * from  voucher_orders where user_id=#{userId}")
    VoucherOrder selectVoucherOrderById(Long userId);

    void addVoucherOrder(VoucherOrder voucherOrder);
    @Update("update voucher set stock=stock-1 where id =#{voucherId}")
    void voucherDedcut(Long voucherId);

    Page<Voucher> pageQuery(VoucherPageQueryDTO voucherPageQueryDTO);
    @Select("select status from voucher where id=#{id}")
    Integer selectVoucherById(Long id);
    @Update("update voucher_orders set status=#{status}  where order_id=#{id}")
    void updateVoucherOrderStatus(Long id, Integer status);
    @Delete("delete  from voucher where id = #{id}")
    void delVoucherById(Long id);

    void UpdateVoucher(Voucher voucher);
    @Select("select stock from voucher where id = #{id}")
    Integer getStockById(Long id);
    @Update("update voucher set stock=stock-1 where id=#{voucherId}")
    void stockIncreById(Long voucherId);
    @Select("select user_id from voucher_orders where order_id=#{orderId} limit 1")
    Integer getUserIdByOrderId(Long orderId);
    @Select("select status from voucher_orders where order_id=#{orderId}")
    Integer getOrderStatusById(Long orderId);
    @Update("update voucher set stock = stock+1 where id =#{voucherId}")
    void voucherStockRollback(Long voucherId);
    @Update("update voucher set status=#{status}  where id=#{id}")
    void updateVoucherStatus(Long id, Integer status);
}
